package com.meryoung.day1;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.GeckoDriverInfo;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;


public class TestNGDemo02 {
    WebDriver driver;
    @BeforeMethod
    public void openchromeCase(){
        //设置chromedriver路径
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\123\\IdeaProjects\\selenium1\\drivers\\chromedriver.exe");
        //实例化Chromedriver
        driver = new ChromeDriver();

    }
    @Test
    public void openChromeTest() throws InterruptedException {
//        //设置浏览器大小，500*500
//        //实例化Dimension，设置窗口大小
//        Dimension dimension = new Dimension(300,500);
//        driver.manage().window().setSize(dimension);
//        //等待5s
//        Thread.sleep(5000);
//        //浏览器最大化
//        driver.manage().window().maximize();
//        //等待5s
//        Thread.sleep(5000);
        //输入网址，打开百度首页
        driver.get("https://www.baidu.com");
        //等待5s
        Thread.sleep(5000);
        //获取当前页面的URL
        String url = driver.getCurrentUrl();
        System.out.println("获取到的URL是："+url);
        Assert.assertEquals(url,"https://www.baidu.com/");
        //等待5s
        Thread.sleep(5000);
//        //刷新操作
//        driver.navigate().refresh();
//        //等待5s
//        Thread.sleep(5000);
//        //后退操作
//        driver.navigate().back();
//        //等待5s
//        Thread.sleep(5000);
//        //前进操作
//        driver.navigate().forward();
//        //等待5s
//        Thread.sleep(5000);
        //关闭当前窗口,不完全
        //driver.close();
        //完全退出
        driver.quit();


    }
    @Test
    public void openFireFoxTest() throws InterruptedException {
        System.setProperty("webdriver.firefox.bin", "E:\\firefox.exe");
        driver = new FirefoxDriver();
        //等待5s
        Thread.sleep(5000);
        //关闭当前窗口
        driver.close();

    }
    @AfterMethod
    public void quiteCase(){
        driver.quit();
    }

}
